<template>
    <div>
        <el-card>
            <div id="echart_main" class="echart_box"></div>
        </el-card>
    </div>
</template>

<script>
    import * as echarts from 'echarts'
    import _ from 'lodash'

    export default {
        data() {
            return {
                options: {},
                defalutOptions: {
                    title: {
                        text: '用户来源'
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                            label: {
                                backgroundColor: '#E9EEF3'
                            }
                        }
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: [
                        {
                            boundaryGap: false
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value'
                        }
                    ]
                }
            }
        },

        created() {
            
        },

        mounted() {
            const myChart = echarts.init(document.getElementById('echart_main'))
            this.getReportData(myChart)
        },

        methods: {
            async getReportData(mychart) {
                const { data: res } = await this.$http.get('reports/type/1')
                if (res.meta.status == 200) {
                    this.options = _.merge(res.data, this.defalutOptions)

                    mychart.setOption(this.options)
                } else {
                    this.$message.error('获取图标数据失败')
                }
            }
        }
    }
</script>

<style lang="less" scoped>
    .echart_box{
        width: 50rem;
        height: 36rem;
    }
</style>